package com.situ.springbootcondition.config;

import com.situ.springbootcondition.pojo.Role;
import com.situ.springbootcondition.pojo.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

@Configuration
public class UserConfig {

    @Bean
    //@Conditional(MyClassCondition.class)
    //将类的判断定义为动态的。判断哪个字节码文件存在可以动态指定。可以指定任何的类
    @MyConditionOnClass("redis.clients.jedis.Jedis")
    //@ConditionalOnProperty(name = "study", havingValue = "java")
    public User user() {
        return new User();
    }

    @Bean
    @MyConditionOnClass("com.alibaba.fastjson.JSON")
    public Role role() {
        return new Role();
    }
}
